package cn.lijiguo.concurrency.part1.threadobjectmethods;

/**
 * Join
 * 演示 join() 注意语句输出顺序 会有变化
 * @author lijiguo
 * @date 2020/1/7 14:08
 */
public class Join {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " 执行完毕！");
        }, "t1");

        Thread t2 = new Thread(() -> {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " 执行完毕！");
        }, "t2");

        t1.start();
        t2.start();
        System.out.println("开始等待子线程执行完毕");
        t1.join();
        t2.join();
        System.out.println("所有子线程已经执行完毕");
    }
}
